package cm.mefobe.android.telecomcost.entities;

import java.util.ArrayList;

import android.util.Log;
import cm.mefobe.android.telecomcost.TelecomCost;

public class Destination {
	private Zone _zone;
	private Country _country;
	private Provider _provider;

	public Destination(Zone zone, Country country, Provider provider) {
		super();
		this._zone = zone;
		this._country = country;
		this._provider = provider;
	}
	
	public static final String PROMPT = "Select a destination";

	public Destination() {
	}

	public void setZone(Zone _zone) {
		this._zone = _zone;
	}

	public Zone getZone() {
		return _zone;
	}

	public void setCountry(Country _country) {
		this._country = _country;
	}

	public Country getCountry() {
		return _country;
	}

	public void setProvider(Provider _provider) {
		this._provider = _provider;
	}

	public Provider getProvider() {
		return _provider;
	}

	@Override
	public String toString() {
		String dest = PROMPT;
		if (_zone != null) {
			dest = _zone.getName();
			if (_country != null) {
				dest = dest + " > " + _country.getName();
				if (_provider != null) {
					dest = dest + " > " + _provider.getName();
				}
			}
		}

		return dest;
	}

	public long getZoneId() {
		return _zone != null ? _zone.getId() : -1;
	}

	public long getCountryId() {
		return _country != null ? _country.getId() : -1;
	}

	public long getProviderId() {
		return _provider != null ? _provider.getId() : -1;
	}

	public ArrayList<VoiceRate> getVoiceRates() {
		Log.i("Destination", "binding voice rates for the destination "
				+ toString());
		
		ArrayList<VoiceRate> _voiceRates = TelecomCost.getDatabaseManager()
				.getVoiceRates();

		ArrayList<VoiceRate> destinationVoiceRates = new ArrayList<VoiceRate>();

		int index = 0;

		while (index < _voiceRates.size()) {
			if (_voiceRates.get(index).getDestinationLabel()
					.equals(toString())) {
				destinationVoiceRates.add(_voiceRates.get(index));
			}
			index++;
		}

		return destinationVoiceRates;
	}
}
